package userdao

import (
	"yundian/internel/app/helper/resphelper/userresp"
	"yundian/internel/pkg/dingo"
	"yundian/internel/pkg/dingo/global"
)


// 修改支付宝openid
func (d *UserDao) UpdateUserZfbOpenidByUserId(param *userresp.PlaceUserInfo) *dingo.ErrorWrap {
	dbInfo := map[string]interface{}{}

	if param.ZfbPhone != "" {
		dbInfo["zfb_phone"] = param.ZfbPhone
	}
	if param.ZfbOpenid != "" {
		dbInfo["zfb_openid"] = param.ZfbOpenid
	}

	db := global.Orm.Table("users")
	db.Where("id = ?", param.UserId)
	db.Updates(dbInfo)

	return dingo.ErrorIf(db.Error)
}

// 获取用户信息
func (d *UserDao) GetPlaceUserInfoByPhone(phone string) *dingo.ErrorWrap {
	m := &userresp.PlaceUserInfo{}
	field := `u.zfb_openid, u.zfb_phone,u.id as user_id, u.name, u.user_name, u.phone, 
	u.is_admin, u.parent_id, u.password, u.is_delete, u.status, u.is_child`
	db := global.Orm.Table("users u").
		Select(field).
		Where("u.phone = ?", phone).
		Find(m)

	return dingo.ErrorIf(db.Error, m)
}
